//引入http模块
const http = require('http');
const url = require('url');

//创建网站服务器对象
const app = http.createServer();
app.on('request',(req, res)=>{
    console.log(req.url);
    console.log(url.parse(req.url, true));
    res.writeHead(200, {
        'content-type' : 'text/html'
    });
    if (req.url == '/index' || req.url == '/'){
        res.end('<h1>welcome to hompage</h1>')
    }else if (req.url == '/list'){
        res.end('welcome to listpage')
    }else {
        res.end('not found')
    }
    //console.log(req.method);
    if (req.method == 'POST'){
        res.end('post')
    }else if (req.method == 'GET'){
        res.end('get')

    }
    /*res.end('<h1>hi.user</h1>'); //res.end结束本次请求*/

});
//监听窗口，没有这个无法访问
app.listen(3000);
console.log('网站服务器启动成功')